/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/** THIS NEEDS TO BE CHANGED TO USE ONLY ONE AXIS ACCELERATION; NOT MAGNITUDE IN ALL DIRECTSIONS **/

package edu.ncsu.csc.sensors;

import com.sun.spot.sensorboard.peripheral.LIS3L02AQAccelerometer;
import com.sun.spot.sensorboard.EDemoBoard;

import java.io.IOException;
/**
 *
 * @author Richard Pospesel
 */
public class SPOTAccelerometer implements Sensor
{
	LIS3L02AQAccelerometer am = (LIS3L02AQAccelerometer)EDemoBoard.getInstance().getAccelerometer();

	double MAX_ACCEL = 6.0;
	char type;

	public SPOTAccelerometer(char type) {
		this.type = type;
		am.setScale(LIS3L02AQAccelerometer.SCALE_6G);
	}

	public char getValue()
	{
		try
		{
			double accel = 0.0;// = am.getAccel();
			switch(type)
			{
				case 'x':
					accel = am.getAccelX();
					break;
				case 'y':
					accel = am.getAccelY();
					break;
				case 'z':
					accel = am.getAccelZ();
					break;
			}
			if (accel > MAX_ACCEL) return 0xFFFF;
			if (accel < -MAX_ACCEL) return 0x0000;
			
			return (char)((accel + MAX_ACCEL)/(2*MAX_ACCEL)*0xFFFF);
		}
		catch(IOException ioe)
		{

		}
		return 0;
	}

	
}
